home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Help With Pointers
- Date: Wed, 21 Feb 96 14:45:02 GMT
- Organization: none
- Message-ID: <824913902snz@genesis.demon.co.uk>
- References: <4g67cj$6cv@hobbes.compusult.nf.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4g67cj$6cv@hobbes.compusult.nf.ca>
- bryan@public.compusult.nf.ca "Barry A. Ryan" writes:
-
- >Hi
- >
- >Is there any way to assign a char pointer to a float pointer?
-
- This is generally dangerous for alignment reasons - it is a much better
- idea to assign a float pointer to a char pointer.
-
- >I had to do some byte rotation on binary data. I rotated
- >the characters and know want to point a float at the first
- >character position to read back a 4 byte float.
-
- Consider:
-
- float value;
- char *ptr = (char *) &value;
-
- You can now consider ptr as pointing to the first element of an array of
- chars indexed from 0 to sizeof(float)-1.
-
- >I'am actually trying to read SGI binary data with a PC. I've been told
- >that the SGI bytes ( not bits ) are rotated versus a PC. Any help
- >would be appreciated. Are the bytes rotated?
-
- I don't know for certain but most likely the byte order is simply reversed
- (big-endian vs. little endian) assuming that they are otherwise compatible.
- Using the pointer set up above it would be very easy to copy the bytes
- into the target float in the order you require.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-